<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use DB;
use Hash;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class OrderController extends Controller
{ 
   // 订单首 页
   public function  getIndex(Request $request)
   {    
        //获取数量 和搜索值
        $num =$request->input('num');
        // var_dump($num);
        $search =$request ->input('search');
        //从数据库中选数组
         $ress =DB::table('project_order')
              ->orWhere('ordernum','like','%'.$search.'%')
              ->orWhere('goodsname','like','%'.$search.'%')
              ->orWhere('orderprice','like','%'.$search.'%')
              ->orWhere('num','like','%'.$search.'%')
              ->get();
        //订单数量
        $m =  count($ress); 
        $arr =array();
        $arr['name']="全部订单";
        $arr['m']=$m;

        $res =DB::table('project_order')
              ->orWhere('ordernum','like','%'.$search.'%')
              ->orWhere('goodsname','like','%'.$search.'%')
              ->orWhere('orderprice','like','%'.$search.'%')
              ->orWhere('num','like','%'.$search.'%')
              ->paginate($request->input('num',10));
              //->get();
         
          
          if($res){
       return view (" /admin/order/index",['row'=>$res,'request'=>$request->all(),'arr'=>$arr]);}
       else{
        return back();
       }
   
   
   }

   public function  getIndex0(Request $request)
   {    
       //获取数量 和搜索值
        $num =$request->input('num');
        // var_dump($num);
        $search =$request ->input('search');
         $ress =DB::table('project_order')
              ->where('status','=',0)
              ->get();
        $m =  count($ress); 
        $arr =array();
        $arr['name']="未付款";
        $arr['m']=$m;


        //从数据库中选数组
        $res =DB::table('project_order')
              ->where('status','=',0)
              ->paginate($request->input('num',10));
          if($res){
       return view (" /admin/order/index",['row'=>$res,'request'=>$request->all(),'arr'=>$arr]);}
       else{
        return back();
       }
   
   }
    public function  getIndex1(Request $request)
   {    
       //获取数量 和搜索值
        $num =$request->input('num');
        // var_dump($num);
        $search =$request ->input('search');
        //从数据库中选数组
          $search =$request ->input('search');
         $ress =DB::table('project_order')
              ->where('status','=',1)
              ->get();
        $m =  count($ress); 
        $arr =array();
        $arr['name']="未发货";
        $arr['m']=$m;


        $res =DB::table('project_order')
              ->where('status','=',1)
              ->paginate($request->input('num',10));
     
         if($res){
       return view (" /admin/order/index",['row'=>$res,'request'=>$request->all(),'arr'=>$arr]);}
       else{
        return back();
       }
   
   
   }
     public function  getIndex2(Request $request)
   {    
       //获取数量 和搜索值
        $num =$request->input('num');
        // var_dump($num);
        $search =$request ->input('search');
         $ress =DB::table('project_order')
              ->where('status','=',2)
              ->get();
         $m =  count($ress); 
        $arr =array();
        $arr['name']="已发货";
        $arr['m']=$m;
        //从数据库中选数组
        $res =DB::table('project_order')
              ->where('status','=',2)
              ->paginate($request->input('num',10));
      
          if($res){
       return view (" /admin/order/index",['row'=>$res,'request'=>$request->all(),'arr'=>$arr]);}
       else{
        return back();
       }
   
   }
     public function  getIndex6(Request $request)
   {    
       //获取数量 和搜索值
        $num =$request->input('num');
        // var_dump($num);
        $search =$request ->input('search');
          $search =$request ->input('search');
         $ress =DB::table('project_order')
              ->where('status','=',6)
              ->get();
       $m =  count($ress); 
        $arr =array();
        $arr['name']="已完成";
        $arr['m']=$m;
        //从数据库中选数组
        $res =DB::table('project_order')
              ->where('status','=',6)
              //->paginate($request->input('num',10));
              ->get();
       
        if($res){
       return view (" /admin/order/index",['row'=>$res,'request'=>$request->all(),'arr'=>$arr]);}
       else{
        return back();
       }
   
   }

      public function  getIndex5(Request $request)
   {    
       //获取数量 和搜索值
        $num =$request->input('num');
        // var_dump($num);
        $search =$request ->input('search');
          $search =$request ->input('search');
         $ress =DB::table('project_order')
              ->where('status','=',5)
              ->get();
        $m =  count($ress); 
        $arr =array();
        $arr['name']="已关闭";
        $arr['m']=$m;
        //从数据库中选数组
        $res =DB::table('project_order')
              ->where('status','=',5)
              ->paginate($request->input('num',10));
              //->get();
      
  
         if($res){
       return view (" /admin/order/index",['row'=>$res,'request'=>$request->all(),'arr'=>$arr]);}
       else{
        return back();
       }

   
   }








//查看详情
   public function getDetail(Request $request)
   {    
      //获取id
      $id =$request->input('id');  //var_dump($id);die;
      //获取订单号的信息
       $ress =DB::table('project_order')->where('id','=',$id)->first();
     
     return view("/admin/order/detail",['row'=>$ress]);
   }

   
   //删除订单
       public function getDelete(Request $request)
       {      
            $id =$request->input('id'); //var_dump($id);
        //从数据库中获取数据
         $res= DB::table('project_order')->where('id',$id)->delete();
            
        //返回值
            if($res){
                  return redirect('/Admin/order/index')->with('success','删除成功'); 
            } else {
                return redirect('/Admin/order/index')->with('error','删除成功');   
            }
           
       }

      // ajax发货操作

        public function getShopping(Request $request)
          { 
            //获取id
            $id =$request->input('id');// var_dump($id);
            //更新数据库的状态
            $res= DB::table('project_order')->where('id',$id)->update(['status'=>'2']);
            // 返回值
              if($res){
                  echo '1';die;
               } else {
                 echo '0' ; die;
              }

          }
}
